﻿using System;
using System.Web.Mvc;
using CashFlow.Entities;
using CashFlow.Entities.Models;
using CashFlow.Repository;
using CashFlow.Web.Controllers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Should.Fluent;

namespace CashFlow.Web.Tests.Controllers
{
	[TestClass]
	public class TenantContollerTest : ControllerTestBase
	{
		private TenantController controller;
		private Mock<ITenantRepository> repositoryMock;
		private ITenantRepository repository;

		private const string IndexViewName = "Index";
		private const string InitialBalanceViewName = "InitialBalance";

		[TestInitialize]
		public void IniTests()
		{
			repositoryMock = new Mock<ITenantRepository>();
			repository = repositoryMock.Object;
			controller = new TenantController(repository);
		}

		#region Initial Balance
		[TestMethod]
		public void Get_On_Success_Should_Redirect_To_Edit()
		{
			var tenant = FakeData.TenantProvider.GetTenant();
			repositoryMock.Setup(x => x.GetById()).Returns(tenant);

			var actual = controller.InitialBalance();

			ShouldRedirectToView(actual, InitialBalanceViewName);
			var view = actual as ViewResult;
			var model = view.Model as InitialBalanceEditModel;
			model.InitialBalanceAmount.Should().Equal(tenant.InitialBalanceAmount);
			model.InitialBalanceDate.Should().Equal(tenant.InitialBalanceDate);
		}

		[TestMethod]
		[Ignore]
		public void Get_On_Exception__________________()
		{
			//TODO: vvs p2 test implementation is incomplete
			repositoryMock.Setup(x => x.GetById()).Throws<Exception>();

			var actual = controller.InitialBalance();

			ShouldRedirectToView(actual, InitialBalanceViewName);
			var view = actual as ViewResult;
			var model = view.Model as InitialBalanceEditModel;
		}
		#endregion

		#region Helpers
		#endregion
	}
}
